import request from '@/utils/request'
import qs from 'qs'
import {Base64} from 'js-base64';

export function login(data) {
  return request({
    url: '/blade-auth/token',
    method: 'post',
    data: qs.stringify(data),
    headers:{
      'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
      "Authorization": `Basic ${Base64.encode(`saber:saber_secret`)}`
    },
  })
}

// 用户注册
export function register(data) {
  return request({
    url: '/blade-auth/register',
    method: 'post',
    data: data,
    headers:{
      "Authorization": `Basic ${Base64.encode(`saber:saber_secret`)}`
    },
  })
}

// 用户新增/修改
export function submit(data) {
  return request({
    url: '/blade-user/submit',
    method: 'post',
    data: data,
  })
}

// 修改密码
export function updatePwd(data) {
  return request({
    url: 'blade-user/update-password ',
    method: 'post',
    data: qs.stringify(data),
    headers:{
      'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
    },
  })
}

// 用户信息
export function getInfo(token) {
  return request({
    url: '/blade-user/info',
    method: 'get',
    params: { token }
  })
}

// 退出登录
export function logout() {
  return request({
    url: '/blade-auth/logout',
    method: 'post'
  })
}

// 用户列表
export function list(params) {
  return request({
    url: '/blade-user/list',
    method: 'get',
    params
  })
}

// 删除用户
export function remove(data) {
  return request({
    url: '/blade-user/remove',
    method: 'post',
    headers:{
      'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
    },
    data: qs.stringify(data),
  })
}